package com.qf.service;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsRegionMapper;
import com.qf.pojo.DtsRegion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author sunyamei
 * @version V1.0
 * @Project javase2203
 * @Package com.qf.service
 * @Description:
 * @Date 2022/7/28 14:09
 */
@Service
public class RegionServiceImpl implements  RegionService {

  @Autowired
   private DtsRegionMapper regionMapper;

    /**
     * 分页查询
     * @param page
     * @param limit
     * @param name
     * @param code
     * @return
     */
    @Override
    public IPage<DtsRegion> queryRegionPage(Integer page, Integer limit, String name, Integer code) {

        //创建分页对象,第一个参数:当前页,第二个参数:每页显示条数
        IPage<DtsRegion> ipage = new Page<>(page,limit);

        //创建查询对象
        QueryWrapper<DtsRegion> queryWrapper = new QueryWrapper<>();

        //判断查询条件是否为空
        if (!StringUtils.isEmpty(name)){
            queryWrapper.eq("name", name);
        }
        if(code != null){
            queryWrapper.eq("code", code);
        }

        //调用mapper
         ipage = regionMapper.selectPage(ipage, queryWrapper);

        return ipage;
    }
}
